const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const resolve = (filePath) => {
  return path.resolve(__dirname, filePath)
}
module.exports = {
  mode: process.env.NODE_ENV,
  entry: resolve('src/main.js'),
  output: {
    path: resolve('dist'),
    filename: 'main.js'
  },
  resolve: {
    extensions: ['.js', '.ts']
  },
  devServer: {
    compress: true,
    port: 9001,
    hot: true
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: 'style-loader'
          },
          {
            loader: 'css-loader'
          }
        ]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: resolve('public/index.html')
    })
  ]
};

